<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2014/11/14
  Time: 14:06
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="spring" uri="/WEB-INF/lib/spring.tld"%>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<html>
<head>
    <title><spring:message code='principalView.index.title' /></title>
    <link href="${path}/style/acg/css/style.css" rel="stylesheet" type="text/css" />
    <script src="${path}/js/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function replaceAll(str){
            if(str != null && str!=""){
                var arr = str.split(",");
                var result="";
                for(var i=0;i<arr.length;i++){
                    if(i == arr.length-1){
                        result += arr[i];
                    }else{
                        result += arr[i]+"<br/>";
                    }
                }
                return result;
            }else{
                return "";
            }

        }
        function getRTime(NowTime,EndTime,obj){
            var timmer;
            var EndTime= new Date(EndTime); //截止时间
            var NowTime = new Date(NowTime);
            var t =EndTime.getTime() - NowTime.getTime();

            var d=Math.floor(t/1000/60/60/24);
            var h=Math.floor(t/1000/60/60%24);
            var m=Math.floor(t/1000/60%60);
            var s=Math.floor(t/1000%60);

            $("#"+obj).html("<spring:message code="home.module2.stay"/>："+d + "天"+h + "时"+m + "分"+s + "秒");
            //setInterval(getRTime(NowTime,EndTime,obj),1000);
            NowTime = new Date(NowTime.getTime()+1000);
            setTimeout(function() {
                getRTime(NowTime,EndTime,obj);
            }, 1000)
        }

    </script>
</head>
<body>
<jsp:include page="../public/header.jsp"></jsp:include>
<!--content-->
<div id="container">
    <div class="wrapper">
        <div class="consignorbasic">
            <div class="consignor_photo">
                <img src="${path}/${priinfos.headPortrait}" width="220" height="220">
            </div>
            <div class="consignor_summary">
                <h1>${priinfos.nickname}</h1>
                <ul>
                    <li>
                        <div class="shuxing">

                            <c:if test="${priinfos.phoneAuth == 101001}">
                                <span><spring:message code='principalView.index.msg1' /></span>
                            </c:if>

                            <c:if test="${priinfos.emailAuth == 101001}">
                                <span><spring:message code='principalView.index.msg2' /></span>
                            </c:if>

                            <c:if test="${priinfos.nameAuth == 101001}">
                                <span><spring:message code='principalView.index.msg3' /></span>
                            </c:if>


                        </div>
                    </li>
                    <li class="op">
                        <a href=""><em class="ico_lx"></em><spring:message code='principalView.index.msg4' /></a>
                        <a href=""><em class="ico_sc"></em><spring:message code='principalView.index.msg5' /></a>
                    </li>
                </ul>
            </div>
            <div class="clr"></div>
        </div>
        <div class="detailmain">
            <div class="detailContent">
                <div class="detailtabs">
                    <ul>
                        <li class="hover" sid="1"><a href="javascript:void(0);"><spring:message code='principalView.index.msg6' /></a></li>
                        <li sid="2"><a href="javascript:void(0);"><spring:message code='principalView.index.msg7' /></a></li>
                        <li sid="3"><a href="javascript:void(0);"><spring:message code='principalView.index.msg8' /></a></li>
                        <li sid="4"><a href="javascript:void(0);"><spring:message code='principalView.index.msg9' /></a></li>
                    </ul>
                </div>
                <div id="tab1" class="tabspack">
                    <div class="projectscon">
                        <p>
                            ${priinfos.intro}
                        </p>
                    </div>
                </div>
                <!--发布任务-->
                <div id="tab2" class="tabspack" style="display: none">
                    <div class="consignor_event">
                        <div class="eventlist">
                            <ul id="taskList2222">

                            </ul>
                        </div>
                    </div>
                </div>
                <!--发布任务-->
                <!--发布竞赛-->
                <div id="tab3" class="Contestlist" style="display: none">
                    <ul class="clearfix" id="raceList">






                    </ul>
                </div>
                <!--发布竞赛-->
                <!--评价-->
                <div id="tab4" class="tabspack" style="display: none">
                    <div class="consignor_event">
                        <div class="event_common">
                            <ul id="appraiseList">

                            </ul>
                        </div>
                    </div>
                </div>
                <!--评价-->
                <div id="kkpager" style="text-align: center;margin-bottom: 20px;"></div>
            </div>
        </div>

    </div>
</div>
<link href="${path}/plugins/page/kkpager.css" rel="stylesheet">
<script src="${path}/plugins/page/kkpager.js" type="text/javascript"></script>
<script>
    var pageSize=8;
    function initBeanInfo2(page, rows) {
        pageSize = rows;
        $.post("${path}/principal/getPrincipTask.html", {
            page: page,
            rows: rows,
            principalId: '${principalId}'
        }, function (data) {
            var list = data.pageInfo.list;
            var htmlstr = "";
            if (list != null) {
                for (var i = 0; i < list.length; i++) {
                    var obj = list[i];
                    var first = '';
                    if(i == 0){
                        first="first";
                    }
                    var daysmsg="<em>"+obj.days+"</em><spring:message code='principalView.index.msg10' />";
                    if(obj.days<0){
                        daysmsg="<spring:message code='principalView.index.msg11' />";
                    }
                    if(obj.description == undefined){
                        obj.description = "";
                    }
                    htmlstr+='<li class="'+first+ ' clearfix">'+
                    '<div class="eventimg"><img src="${path}/'+obj.itemPic+'" width="170" height="104"></div>'+
                    '<div class="eventcon">'+
                    '<h3>'+obj.title+'</h3>'+
                    '<div class="shuxing"><span><em class="ing"></em>'+obj.itemStatus+'</span></div>'+
                    '<p>'+obj.description+'</p>'+
                    '</div>'+
                    '<div class="eventmoney"><spring:message code='principalView.index.msg12' /><em>￥'+obj.budget+'</em></div>'+
                    '<div class="eventtime">'+
                    '        <p><em class="ico_user"></em><em>'+obj.persons+'</em><spring:message code='principalView.index.msg13' /></p>'+
                    '<p><em class="ico_rili"></em>'+daysmsg+'</p>'+
                    '</div>'+
                    '<div class="clr"></div>'+
                    '</li>';
                }
                $("#taskList2222").html(htmlstr);
                var pager = data.pageInfo;
                //分页
                createPage(pager.pageNum, pager.pages, pager.total,initBeanInfo2);
                $("#kkpager").show();
            }

        },"json");
    }

    function initBeanInfo3(page, rows) {
        pageSize = rows;
        $.post("${path}/principal/getPrincipRace.html", {
            page: page,
            rows: rows,
            principalId: '${principalId}'
        }, function (data) {
            var list = data.pageInfo.list;
            var htmlstr = "";
            if (list != null) {
                for (var i = 0; i < list.length; i++) {
                    var obj = list[i];
                    htmlstr+='<li>'+
                    '<a href="${path}/racedetail/index.html?raceId=2"><img src="${path}/'+obj.task_pic+'" onlick="" width="292" height="180"></a>'+
                    '<h3><a href="${path}/racedetail/index.html?raceId=2">'+obj.title+'</a></h3>'+
                    '<div class="time" id="race'+i+'"><spring:message code='principalView.index.msg14' />'+getRTime(obj.startTime,obj.endTime,"race"+i)+'</div>'+
                    '<div class="txt">'+replaceAll(obj.name)+
                    '</div>'+
                    '<div class="read"><a href="${path}/racedetail/index.html?raceId=2"><spring:message code='principalView.index.msg15' /></a></div>'+
                    '</li>';
                }
                $("#raceList").html(htmlstr);
                var pager = data.pageInfo;
                //分页
                createPage(pager.pageNum, pager.pages, pager.total,initBeanInfo2);
                $("#kkpager").show();
            }

        },"json");
    }

    function initBeanInfo4(page, rows) {
        pageSize = rows;
        $.post("${path}/principal/getPrincipAppraise.html", {
            page: page,
            rows: rows,
            principalId: '${principalId}'
        }, function (data) {
            var list = data.pageInfo.list;
            var htmlstr = "";
            if (list != null) {
                for (var i = 0; i < list.length; i++) {
                    var obj = list[i];
                    htmlstr+='<li class="first clearfix">'+
                    '<div class="cimg"><img src="${path}/'+obj.headPortrait+'" width="70" height="70"></div>'+
                    '<div class="common_con">'+
                    '<h3>'+obj.title+'<em><spring:message code='principalView.index.msg16' /><font class="color_red">￥'+obj.totalPrice+'</font></em><span>'+obj.appraiseTime+'</span></h3>'+
                    '<p>'+obj.content+'</p>'+
                    '</div>'+
                    '<div class="clr"></div>'+
                    '</li>';
                }
                $("#appraiseList").html(htmlstr);
                var pager = data.pageInfo;
                //分页
                createPage(pager.pageNum, pager.pages, pager.total,initBeanInfo4);
                $("#kkpager").show();
            }

        },"json");
    }



    //分页方法
    //currentPage 当前页
    //rows 每页条数
    //total 总数
    function createPage(currentPage, totalPage, totalCount,fn) {
        var totalPage = totalPage;
        var totalRecords = totalCount;
        var pageNo = currentPage;
        if (!pageNo) {
            pageNo = 1;
        }
        //生成分页
        //有些参数是可选的，比如lang，若不传有默认值
        kkpager.generPageHtml({
            pno: pageNo,
            //总页码
            total: totalPage,
            //总数据条数
            totalRecords: totalRecords,
            //链接前部
            hrefFormer: 'index',
            //链接尾部
            hrefLatter: '',
            //是否显示总页数
            isShowTotalPage: true,
            //是否显示总记录数
            isShowTotalRecords: true,
            //是否显示页码跳转输入框
            isGoPage: true,
            //getLink: function (n) {
            //    return this.hrefFormer + this.hrefLatter + "?pno=" + n;
            //}
            //,
            mode : 'click',//默认值是link，可选link或者click
            click : function(n){
                //this.selectpage(n);
                fn(n, pageSize);
                return false;
            },
            lang				: {
                firstPageText			: '<spring:message code="firstPageText"/>',
                firstPageTipText		: '<spring:message code="firstPageTipText"/>',
                lastPageText			: '<spring:message code="lastPageText"/>',
                lastPageTipText			: '<spring:message code="lastPageTipText"/>',
                prePageText				: '<spring:message code="prePageText"/>',
                prePageTipText			: '<spring:message code="prePageTipText"/>',
                nextPageText			: '<spring:message code="nextPageText"/>',
                nextPageTipText			: '<spring:message code="nextPageTipText"/>',
                totalPageBeforeText		: '<spring:message code="totalPageBeforeText"/>',
                totalPageAfterText		: '<spring:message code="totalPageAfterText"/>',
                totalRecordsAfterText	: '<spring:message code="totalRecordsAfterText"/>',
                gopageBeforeText		: '<spring:message code="gopageBeforeText"/>',
                gopageButtonOkText		: '<spring:message code="gopageButtonOkText"/>',
                gopageAfterText			: '<spring:message code="gopageAfterText"/>',
                buttonTipBeforeText		: '<spring:message code="buttonTipBeforeText"/>',
                buttonTipAfterText		: '<spring:message code="buttonTipAfterText"/>'
            }
        },true);
    }
    $(function(){
        //切换tab
        $("div.detailtabs ul li").click(function(){
            $("div.detailtabs ul li.hover").each(function(){
                    var sid = $(this).attr("sid");
                    $("#tab"+sid).hide();
                    $(this).removeClass("hover");
            });
            $(this).addClass("hover");
            var cslid = $(this).attr("sid");
            $("#tab"+cslid).show();
            if(cslid==2){
                initBeanInfo2(1,10);
            }else if(cslid==3){
                initBeanInfo3(1,10);
            }else if(cslid==4){
                initBeanInfo4(1,10);
            }
        });
    });


</script>
<!--content-->
<jsp:include page="../public/footer.jsp"></jsp:include>
</body>
</html>
